package com.ssy.lingxi.contract.utils;

import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.contract.model.constant.ContractPayWayEnum;

/**
 * 入参公共校验类
 * @author ds
 * @version 2.0.0
 * @date 2021/4/26
 */
public class ParamVerifyUtils {

    private static boolean isValidScope(int start,int end,Integer param){
        if(param==null){return Boolean.FALSE;}
        return param>=start&&param<=end;
    }

    /**
     * 校验支付方式
     * @param payWay
     * @param payParam
     * @return
     */
    public static void checkPayWay(Integer payWay,Integer payParam){
        ContractPayWayEnum contractPayWayEnum = ContractPayWayEnum.find(payWay);
        if(contractPayWayEnum==null){
            throw new BusinessException(ResponseCode.CONTRACT_APPLY_AMOUNT_ORDER_PAY_WAY_ERROR);
        }else if(contractPayWayEnum.equals(ContractPayWayEnum.PAYMENT_DAYS)){//账期
            if(payParam==null||payParam<=0){
                throw new BusinessException(ResponseCode.CONTRACT_APPLY_AMOUNT_ORDER_PAY_WAY_PARAM_ERROR);
            }
        }else if(contractPayWayEnum.equals(ContractPayWayEnum.MONTH_SETTLEMENT)){//月结
            if(!isValidScope(1,31,payParam)){
                throw new BusinessException(ResponseCode.CONTRACT_APPLY_AMOUNT_ORDER_PAY_WAY_PARAM_ERROR);
            }
        }
    }
}
